/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;
/**
 *
 * @author ipti
 */
@Entity
public class Alias extends AbstractEntity{
    
    @Column(name = "value")
    private String value;
    
    @JoinTable(name = "questalias", joinColumns = {
        @JoinColumn(name = "hash_id_alias", referencedColumnName = "hash_id")}, inverseJoinColumns = {
        @JoinColumn(name = "hash_id_quest", referencedColumnName = "hash_id")})
    @ManyToMany
    private List<QuestResult> questResultList;
    
    @ManyToOne
    @JoinColumn(name = "ask_id")
    private Asks ask;
    
    public Alias() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = "" + this.getValue() + this.getAsk();
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }
    
    public Alias(String value, Asks ask) {
        this.value = value;
        this.ask = ask;
    }

    public Asks getAsk() {
        return ask;
    }

    public void setAsk(Asks ask) {
        this.ask = ask;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
    
    public List<QuestResult> getQuestresultList() {
        return questResultList;
    }

    public void setQuestresultList(List<QuestResult> questresultList) {
        this.questResultList = questresultList;
    }

    public List<QuestResult> getQuestResultList() {
        return questResultList;
    }

    public void setQuestResultList(List<QuestResult> questResultList) {
        this.questResultList = questResultList;
    }
}
